Solving 10385 - Duathlon (Ternary search)
[andmenj-acm.git] / 270 - Lining Up / 270.cpp
blob834c1ba51c8f3dd2c085d64f7fb379d078933a36
1 /*
2 Problem: 270 - Lining up
3 Andrés Mejía-Posada (andmej@gmail.com)
5 Time limit exceeded.
6 */
7 using namespace std;
8 #include <algorithm>
9 #include <iostream>
10 #include <iterator>
11 #include <sstream>
12 #include <fstream>
13 #include <cassert>
14 #include <climits>
15 #include <cstdlib>
16 #include <cstring>
17 #include <string>
18 #include <cstdio>
19 #include <vector>
20 #include <cmath>
21 #include <queue>
22 #include <deque>
23 #include <stack>
24 #include <list>
25 #include <map>
26 #include <set>
28 #define D(x) cout << #x " is " << x << endl
30 struct point{
31 int x, y;
32 point(int x=0, int y=0) : x(x), y(y) {}
35 inline void simplify(pair<int, int> &p){
36 #define x first
37 #define y second
38 if (p.y == 0){
39 p.x = 1;
40 return;
42 if (p.x == 0){
43 p.y = 1;
44 return;
46 int sign = ((p.x<0)^(p.y<0) ? -1 : 1);
47 if (p.x < 0) p.x *= -1;
48 if (p.y < 0) p.y *= -1;
49 int g = __gcd(p.x, p.y);
50 if (g) p.x /= g, p.y /= g;
51 p.x *= sign;
52 #undef x
53 #undef y
56 char buf[512];
58 int main(){
59 int cases;
60 fgets(buf, 512, stdin);
61 sscanf(buf, "%d", &cases);
62 fgets(buf, 512, stdin);
63 while (cases--){
64 vector<point> p;
65 while (fgets(buf, 512, stdin) != NULL && strcmp(buf, "\n")){
66 point _;
67 sscanf(buf, "%d %d", &_.x, &_.y);
68 p.push_back(_);
71 int x = 0;
72 map<pair<int, int>, int> cnt;
73 const int n = p.size();
74 for (int i=0; i<n; ++i){
75 for (int j=i+1; j<n; ++j){
76 pair<int, int> slope(p[j].y - p[i].y, p[j].x - p[i].x);
77 simplify(slope);
78 x = max(x, ++cnt[slope]);
82 printf("%d\n", (int)((1 + sqrt(1 + 8*x))/2));
83 if (cases > 0) puts("");
85 return 0;